package model

import "gorm.io/gorm"

type User struct {
	gorm.Model
	PhoneNum      string `gorm:"type:char(11);not null"`
	Password      string `gorm:"type:varchar(32);not null"`
	Nickname      string `gorm:"type:varchar(32);not null"`
	AvatarLink    string `gorm:"type:varchar(500)"`
	AccountStatus int    `gorm:"type:int;default:0"`
	FollowNum     int    `gorm:"type:int;default:0"`
	FansNum       int    `gorm:"type:int;default:0"`
}

func (u *User) FindUserByPhone(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone_num=?", phone).Find(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UpdatePassword(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone_num=?", phone).Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(u).Error

}

func (u *User) UpdateUser(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Updates(u).Error
}
